import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { WindowEvent } from "../../../component/window/WindowEvent";
import { CrossGuildWarCache } from "../../cache/CrossGuildWarCache";
import { Cache } from "../../cache/Cache";
import { CrossGuildWarChooseForTopSubWin } from "./subWin/CrossGuildWarChooseForTopSubWin";
import { GameProxy } from "../../mvc/GameProxy";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { CrossGuildWarScheduleRank } from "./subWin/CrossGuildWarScheduleRank";
import { GSprite } from "../../../../com/mui/controls/GSprite";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { ObjCreate } from "../common/ObjCreate";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GTabBar } from "../../../../com/mui/controls/GTabBar";
type int = number;
//class CrossGuildWarModule
    
    export  class CrossGuildWarModule extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(839, 588);
            this.title = Language.getString(80550);
            this.titleHeight = 48;
            this.addEventListener(WindowEvent.CLOSE, this.onClose);
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAdd);
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose(arg1);
            if (this._rankWin != null) 
            {
                this._rankWin.dispose(arg1);
                this._rankWin = null;
            }
            return;
        }

        public updateTabEnables(arg1: Array<any>): void
        {
            return;
        }

        public getTabSelected(): int
        {
            if (this._tab == null) 
            {
                return 0;
            }
            return this._tab.selectedIndex;
        }

        public setTabSelected(arg1: int): void
        {
            if (this._tab == null) 
            {
                return;
            }
            if (arg1 > 1) 
            {
                return;
            }
            this._tab.selectedIndex = arg1;
            return;
        }

        /* internal  */get cache(): CrossGuildWarCache
        {
            return Cache.instance.crossGuildWar;
        }

        public showChooseForTopWin(): void
        {
            if (this._chooseForTopWin == null) 
            {
                this._chooseForTopWin = new CrossGuildWarChooseForTopSubWin();
            }
            this._chooseForTopWin.updateSelfGuild(this.cache.getSelfGuildData(), this.cache.getSelfCurFightStatus());
            this._chooseForTopWin.updateEnemyGuild(this.cache.getEnemyGuildData(), this.cache.getEnemyCurFightStatus());
            if (this.cache.curStage < 10) 
            {
                this._chooseForTopWin.updateList(this.cache.curStage, this.cache.getChooseEnemyData());
            }
            else 
            {
                this._chooseForTopWin.updateList(this.cache.curStage, this.cache.getLiveDatas(this.cache.curStage));
                GameProxy.copy.crossGuildWarGetMatchInfos(1, 100);
            }
            this._chooseForTopWin.updateStatusTips(this.cache.getFingtStatusParams());
            this._chooseForTopWin.updateTopBtns(this.cache.getChooseForTopBtnDatas());
            this.showWin(this._chooseForTopWin);
            return;
        }

        public updateTopBtns(arg1: Array<any>): void
        {
            if (this._chooseForTopWin == null) 
            {
                return;
            }
            this._chooseForTopWin.updateTopBtns(arg1);
            return;
        }

        public updateLiveData(arg1: DataProvider, arg2: int): void
        {
            if (this._chooseForTopWin == null) 
            {
                return;
            }
            this._chooseForTopWin.updateList(arg2, arg1);
            return;
        }

        public get chooseForTopWin(): CrossGuildWarChooseForTopSubWin
        {
            if (this._chooseForTopWin == null) 
            {
                this._chooseForTopWin = new CrossGuildWarChooseForTopSubWin();
            }
            return this._chooseForTopWin;
        }

        public showRankWin(arg1: int, arg2: DataProvider, arg3: int, arg4: int): void
        {
            if (this._rankWin == null) 
            {
                this._rankWin = new CrossGuildWarScheduleRank();
            }
            this._rankWin.updateMaxPageShow(arg1);
            this._rankWin.updateGuildNum(arg3);
            this._rankWin.updateGuildPlace(arg4);
            this._rankWin.updateData(arg2);
            this.showWin(this._rankWin);
            return;
        }

        public getRankCurPage(): int
        {
            if (this._rankWin == null) 
            {
                return 1;
            }
            return this._rankWin.getCurPage();
        }

        public showWin(arg1: GSprite): void
        {
            if (this._curShowing != arg1) 
            {
                DisplayUtil.removeMe(this._curShowing);
            }
            this._curShowing = arg1;
            this._curShowing.x = 18;
            this._curShowing.y = 60;
            this.addChild(this._curShowing);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._tab = ObjCreate.createGTabBar(22, 35, Language.getArray(80549), 65, 21, this);
            this._tab.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.tabChangeHandler);
            return;
        }

        /* internal  */tabChangeHandler(arg1: MuiEvent): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGuildWarModuleTabChange, this._tab.selectedIndex));
            return;
        }

        /* internal  */onAdd(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGuildWarIsNotice, true));
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarIsNotice, true));
            return;
        }

        /* internal  */onClose(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGuildWarIsNotice, false));
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarIsNotice, false));
            return;
        }

        /* internal */ /* var */_tab: GTabBar;

        /* internal */ /* var */_rankWin: CrossGuildWarScheduleRank;

        /* internal */ /* var */_chooseForTopWin: CrossGuildWarChooseForTopSubWin;

        /* internal */ /* var */_curShowing: GSprite;
    }
